from django import forms


class StarkModelForm(forms.ModelForm):
    """
    ModelForm 为每个input添加class
    """
    def __init__(self, *args, **kwargs):
        super(StarkModelForm, self).__init__(*args, **kwargs)
        # 添加 class 类
        for name, field in self.fields.items():
            # 复选框添加title属性
            if field.widget.input_type == 'checkbox':
                field.widget.attrs['title'] = field.label
            field.widget.attrs['class'] = 'layui-input'
